package com.ojtest.demo;

public class code1 {
    public static void main(String[] args) {

    }
    public static boolean canPartition(int[] nums) {
        int n = nums.length, sum = 0;
        for (int number : nums)
            sum += number;
        if (sum % 2 == 1)
            return false;
        sum /= 2;

        boolean[] dp = new boolean[sum + 1];
        dp[0] = true;
        for (int i = 1; i < n + 1; i++) {
            for (int j = sum; j >= nums[i - 1]; j--) {
                dp[j] |= (dp[j] || dp[j - nums[i - 1]]);
            }
            if (dp[sum])
                break;
        }
        return dp[sum];
    }
}
